# app/app.py
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

from app.core.database import engine
from app.models.models import Base
from app.api.routes import auth, students, machines, sessions, computer_rooms

# 创建数据库表
Base.metadata.create_all(bind=engine)

# 创建FastAPI应用实例
app = FastAPI(title="机房管理系统", version="1.0.0")

# CORS配置
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# 注册路由
app.include_router(auth.router, prefix="/auth", tags=["认证"])
app.include_router(students.router, prefix="/students", tags=["学生管理"])
app.include_router(machines.router, prefix="/machines", tags=["机器管理"])
app.include_router(sessions.router, prefix="/sessions", tags=["上机管理"])
app.include_router(computer_rooms.router, prefix="/computer-rooms", tags=["机房管理"])

# 根路径
@app.get("/", tags=["首页"])
def read_root():
    return {"message": "机房管理系统 API", "version": "1.0.0"}